package com.sdy.resdir.biz.util;

import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hyh
 */
@Data
public class PageUtil<T> {
    /**
     * 数据总条数
     */
    private long total = 0;
    /**
     * 分页大小
     */
    private long size = 10;
    /**
     * 当前页数
     */
    private long current = 1;
    /**
     * 总页数
     */
    private long pages = 0;
    /**
     * 结果集
     */
    private List<T> records;

    private void init(long size, long current, List<T> notices) {
        this.size = size;
        this.current = current;
        this.total = notices.size();
        if (total % size > 0) {
            this.pages = (total / size) + 1;
        } else {
            this.pages = total / size;
        }
    }

    private void records(List<T> notices) {
        records = notices.stream().limit(current * size).skip((current - 1) * size).collect(Collectors.toList());
    }

    public PageUtil(long size, long current, List<T> notices) {
        init(size, current, notices);
        records(notices);
    }

}